<?php framework::view('index/header')?>
<script type="text/javascript">
function save(){
    <?php if (!$row){?>
    var url = '<?php echo HIGHPHP_WWW_HOST?>user/bank/do/save';
    <?php }else{?>
    var url = '<?php echo HIGHPHP_WWW_HOST?>user/bank/do/save/id/<?php echo $row['id'];?>';
    <?php }?>
    var name = $.trim($("#name").val());
    var paytype = $.trim($("#paytype").val());
    if(paytype=='支付宝'){
    	bankname='支付宝';
    }else{
        var bankname = $.trim($("#bankname").val());
    }
    var branch = $.trim($("#branch").val());
    var bankno = $.trim($("#bankno").val()); 

    var province = $.trim($("#province").val());
	var city = $.trim($("#city").val());
	var area = $.trim($("#area").val());
    var phone = $.trim($("#phone").val());
    var isdefault = $("#isdefault").attr('checked');     
    if(!name){
        amsg('请填帐号所有人姓名'); 
        $("#name").focus();
        return false;   
    }    
    if(!bankname){
       	 amsg('请选择银行'); 
         $("#bankname").focus();
         return false;   
    }
    if(!bankno){
        amsg('请填帐号'); 
        $("#bankno").focus();
        return false;   
    }    
    $.post(url,{'name':name,'paytype':paytype,'bankname':bankname,'branch':branch,'bankno':bankno,'province':province,'city':city,'area':area,'phone':phone,'isdefault':isdefault
        },function(rs){
        amsg(rs);        
    })
}
function setdefault(id){
    var url = '<?php echo HIGHPHP_WWW_HOST;?>user/setdeaultaddr/id/'+id;
    $.get(url,function(rs){
        amsg(rs);
    })
}
function changePaytype(){
    if($("#paytype").val()=='支付宝'){
        $(".fenhang").fadeOut();
        $("#kardname").html('支付宝账号');
        $("#bankinfo").hide();
    }else{
    	$(".fenhang").fadeIn();
    	$("#kardname").html('银行卡号');
    	$("#bankinfo").show();
    }
}
</script>
<?php framework::view('index/userleft')?>
        <div style="" class="lrtab">    
        <a href="<?php echo HIGHPHP_WWW_HOST?>user"   style="border-left: solid 1px #DFDFDF">基本信息</a>
        <a href="<?php echo HIGHPHP_WWW_HOST?>user/basicinfo" >个人资料</a>
        <a href="<?php echo HIGHPHP_WWW_HOST?>user/address">收货地址</a>
        <a href="<?php echo HIGHPHP_WWW_HOST?>user/bank" class="lrtabon" >收款信息</a>
        </div>
        <div class="clear"></div>
        <div style="padding-top:10px;width:100%;background: #f3f3f3;padding-bottom:10px;text-align: left;"><span style="font-size: 14px;font-weight:bold;padding-left:10px;">新增收款信息</span></div>
        <div>
            <form onsubmit="save();return false;">
                <table style="width: 100%">
                    <tr>
                        <td align="right" style="width:150px;">*姓名：</td>
                        <td ><input type="text" name="name" id="name" class="logintext" tabindex="1" <?php if ($row){ echo 'value="'.$row['name'].'"';}?>></td>
                        <td>&nbsp;</td>
                    </tr>
                    <tr>
                        <td align="right">*选择收款方式：</td>
                        <td><select id="paytype" name="paytype" onchange="changePaytype()"  tabindex="2" >
                        <option value="支付宝" <?php if ($row){if ($row['bankname']=='支付宝'){echo ' selected="selected"';}}?>>支付宝</option>
                        <option value="银行" <?php if ($row){if ($row['bankname']!='支付宝'){echo ' selected="selected"';}}?>>银行</option>
                        </select>
                        
                        </td>
                        <td>&nbsp;</td>
                    </tr>
                     <tr class="fenhang" style="display: none;">
                        <td align="right">银行所在地：</td>
                        <td valign="top">
                        <span id="bankinfo" style="display: none;"><select id="province" name="province"  tabindex="3" ></select>省 <select id="city" name="city"  tabindex="4" ></select>市 <select id="area" name="area"  tabindex="5" ></select>区
                        <script type="text/javascript">   
                        <?php if ($row){?>
                        addressInit('province', 'city', 'area','<?php echo $row['province'];?>','<?php echo $row['city'];?>','<?php echo $row['area'];?>');
                        <?php }else{?>
                        addressInit('province', 'city', 'area');
                        <?php }?>
                        </script>
                            
                        </span>
                        </td>
                        <td>&nbsp;</td>
                    </tr>
                    <tr class="fenhang" style="display: none;">
                        <td align="right">银行名称：</td>
                        <td valign="top">
                        <select id="bankname" name="bankname" tabindex="6" >
                                <option value="">请选择银行</option>
                                <option value="中国招商银行" <?php if ($row){if ($row['bankname']=='中国招商银行'){echo ' selected="selected"';}}?>>中国招商银行</option>
                                <option value="中国建设银行" <?php if ($row){if ($row['bankname']=='中国建设银行'){echo ' selected="selected"';}}?>>中国建设银行</option>
                                <option value="中国农业银行" <?php if ($row){if ($row['bankname']=='中国农业银行'){echo ' selected="selected"';}}?>>中国农业银行</option>
                                <option value="中国人民银行" <?php if ($row){if ($row['bankname']=='中国人民银行'){echo ' selected="selected"';}}?>>中国人民银行</option>
                                <option value="中国工商银行" <?php if ($row){if ($row['bankname']=='中国工商银行'){echo ' selected="selected"';}}?>>中国工商银行</option>
                        </select> <span class="logintips" style="padding-top:7px;display: inline-block;color:#333">分行：</span><input type="text" name="branch" id="branch" class="logintext4" tabindex="6" <?php if ($row){ echo 'value="'.$row['branch'].'"';}?>>
                        
                        <span class="logintips" style="padding-top:7px;display: inline-block;">填写分行会更快收到款项</span></td>
                        <td>&nbsp;</td>
                    </tr>
                    <tr>
                        <td align="right">*<span id="kardname">支付宝帐号</span>：</td>
                        <td><input type="text" name="bankno" id="bankno" class="logintext" tabindex="7" <?php if ($row){ echo 'value="'.$row['bankno'].'"';}?>></td>
                        <td>&nbsp;</td>
                    </tr>
                    <tr>
                        <td align="right">接收短信手机：</td>
                        <td><input type="text" name="phone" id="phone" class="logintext2" tabindex="9" <?php if ($row){ echo 'value="'.$row['phone'].'"';}?>>
                        <span class="logintips">用于打款通知</span>
                        </td>
                        <td>&nbsp;</td>                        
                    </tr>
                    
                    <tr>
                        <td align="right">设为默认：</td>
                        <td><input type="checkbox"" name="isdefault" id="isdefault" tabindex="10" <?php if ($row){ if ($row['isdefault']=='1'){ echo ' checked="checked"';}}?>></td>
                        <td>&nbsp;</td>
                    </tr>
                    <tr>
                        <td align="right">&nbsp;</td>
                        <td><input type="submit" value="保 存" class="regbtn" tabindex="11"></td>
                        <td>&nbsp;</td>
                    </tr>
                </table>
            </form>
        </div>
        <div style="padding-top:10px;width:100%;background: #f3f3f3;padding-bottom:10px;text-align: left;"><span style="font-size: 14px;font-weight:bold;padding-left:10px;">已经保存的收款信息</span></div>
        <table width="100%" cellpadding="3" cellspacing="1" class="ctable">
            <tr class="tr2">
                <th style="width:100px;" align="center">收款人</th>
                <th style="width:160px;" align="center">收款方式</th>
                <th style="width:160px;" align="center">收款帐号</th>                           
                <th align="center">接收短信手机</th>               
                <th align="center">操作</th>
            </tr>
            <?php foreach ($rs as $k=>$v):?>
            <tr class="tr1">
                <td align="center" valign="middle"><?php echo $v['name'];?></td>
                <td align="center" valign="middle"><?php echo $v['bankname'];?> <?php echo $v['branch'];?>
                <?php if ($v['bankname']!='支付宝'){?>
                <br><?php echo $v['province'];?> - <?php echo $v['city'];?> - <?php echo $v['area'];}?>
                </td>
                <td align="center"  valign="middle"><?php echo $v['bankno'];?></td>
                <td align="center" valign="middle"><?php echo $v['phone'];?></td>
                <td align="center" valign="middle"><?php if ($v['isdefault']){ echo '<span style="color:green;">默认帐号</span>';}else{?><a href="javascript:setdefault('<?php echo $v['id']?>')">设为默认</a><?php }?> <a href="<?php echo HIGHPHP_WWW_HOST?>user/bank/do/edit/id/<?php echo $v['id'];?>">修改</a> | <a href="">删除</a></td>
            </tr>
            <?php endforeach;?>
        </table>
        <script type="text/javascript">
        <?php if ($row){        
            ?>
            changePaytype();
        <?php }?>
        </script>
<?php framework::view('index/userfooter')?>
<?php framework::view('index/footer')?>